package com.taxsystem.yehao.activity;

import java.util.HashMap;
import java.util.List;

import com.taxsystem.yehao.jsonParser.BranchListParser;
import com.taxsystem.yehao.tool.UrlHost;
import com.main.taxsystem.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class BranchListActivity extends BaseListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.branch_list_yh);
		lv = (ListView) findViewById(R.id.branch_list_view);
		progressBar = (ProgressBar) findViewById(R.id.branch_list_progressBar);
		this.setProcessBarVisible(true);
		new Thread() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				simpleAdapter = new SimpleAdapter(BranchListActivity.this,getData(),R.layout.branch_list_item_yh,
						new String[] {"branchId","branchName","address","longitude","latitude"}
						,new int[]{R.id.branch_list_branchId,R.id.branch_list_branchName,R.id.branch_list_address,R.id.branch_list_longitude,R.id.branch_list_latitude});
				BranchListActivity.this.setListAdapter();
				BranchListActivity.this.setProcessBarVisible(false);
			}
			
		}.start();
		
		
		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				String branchId = ((TextView)view.findViewById(R.id.branch_list_branchId)).getText().toString();
				Intent intent = new Intent(BranchListActivity.this,CalendarActivity.class);
				intent.putExtra("branchId", branchId);
				startActivity(intent);
			}
			
		});
		
	}
	private List<HashMap<String,Object> > getData() {
		List <HashMap<String,Object >> list = BranchListParser.parse(UrlHost.host+"/app/branch/branchgilist",null);
		return list;
	}
}
